package cn.edu.sdjzu.xg.eagle.Test;

import cn.edu.sdjzu.xg.eagle.Service.CommonDaoService;
import cn.edu.sdjzu.xg.eagle.dao.CommonDao;
import cn.edu.sdjzu.xg.eagle.entity.Condition;
import cn.edu.sdjzu.xg.eagle.util.JdbcHelper;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CommonDaoTest {
    public static void main(String[] args) throws SQLException {
        Connection conn = null;
        try {
            //获取连接
            conn = JdbcHelper.getConn();

            //通过工厂获得CommonDao对象
            CommonDaoService commonDao = CommonDao.getInstance();


            //获取School表中的总记录条数
            int schoolRowNumber = commonDao.countAll(conn,"school");
            System.out.println("School表总记录数:" + schoolRowNumber);

            //带条件的查询语句(子句)
            Condition departmentCondition = new Condition("school_id","1","=");

            //构建条件列表
            List<Condition> conditionList = new ArrayList<>();

            //将条件添加到列表中
            conditionList.add(departmentCondition);

            //
            int departmentRowNumber = commonDao.count(conn,"department",conditionList);
            System.out.println("符合条件的department记录数:" + departmentRowNumber);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            JdbcHelper.close(conn);
        }

    }
}
